home *** CD-ROM | disk | FTP | other *** search
Wrap
/* ** $VER: Preserve.ieb 2.0, IE Arexx script ** Image Engineer Batch Processing script ** Copyright © by Patrik M Nydensten ** 19/1 1997 Stockholm/Sweden ** ** Presereve colors within selected hue range(s). ** Based on the IE arexx script Presereve 2.13. */ options results signal on error parse arg input command input = upper(strip(input)) address 'IMAGEENGINEER' select /* Required batch script commands */ when input = 'INFO' then return get_info() when input = 'CONFIG' then return get_config(command) when input = 'PROCESS' then return process_image(command) otherwise do 'REQUEST' '"Failure in call to batch script!"' '" Quit "' return '<ERROR>' end end exit 0 /* Required "Get_info" procedure ------------------------------------ */ /* S = SECONDARY, A = ALPHA, 1 = Single file, 2 = Multiple files */ get_info: back = 'OK' return back /* Required "Get_config" procedure ---------------------------------- */ get_config: parse arg '"'command'"' LHueTol=-21 ; RHueTol=21 if command ~= '' then parse var command LHueTol RHueTol '#'Select '#'WorkType . 'IE_TO_FRONT' form = 'FORM "Preserve" " Accept | Cancel "', ' TEXT,"Preserves selected basecolors in image while'd2c(10)'unselected colors are made grey."' if command = '' then form = form ||' CHECKBOX,"Red (R)",1', ' CHECKBOX,"Yellow (Y)",0', ' CHECKBOX,"Green (G)",1', ' CHECKBOX,"Cyan (C)",0', ' CHECKBOX,"Blue (B)",1', ' CHECKBOX,"Magenta (M)",0' form = form ||' INTEGER,"Left hue tolerance",-21,0,'strip(LHueTol)',SLIDER', ' INTEGER,"Right hue tolerance",0,21,'strip(RHueTol)',SLIDER' if command = '' then form = form ||' CYCLE,"Work type:",'||, '"Fields, (separate color areas)|Spread, (use areas between close colors)",0' form if command = '' then do parse var result ok R Y G C B M LHueTol RHueTol WorkType . Select = '' if R then Select = Select||'R' else Select = Select||'-' if Y then Select = Select||'Y' else Select = Select||'-' if G then Select = Select||'G' else Select = Select||'-' if C then Select = Select||'C' else Select = Select||'-' if B then Select = Select||'B' else Select = Select||'-' if M then Select = Select||'M' else Select = Select||'-' end else do parse var result ok LHueTol RHueTol . Select = '------' WorkType = 'none' end if ok = 0 then return '<ERROR>' back = LHueTol RHueTol '#'Select '#'WorkType return back /* Required "Process_image" procedure ------------------------------- */ process_image: parse arg '"'src_image'"' '"'dst_image'"' '"'options'"' parse var options LHueTol RHueTol '#'Select '#'WorkType . 'OPEN' '"'src_image'"' '24' if (RC ~= 0) then do 'IE_TO_FRONT' 'REQUEST' '"Failed to load image:' d2c(10)||src_image'"' '" OK "' return '<ERROR>' end else LoadImage = result 'BRIGHTNESS' LoadImage '-255' AlphaImage = Result do i = 0 to 5 /* alpha add-loop */ if substr(Select,i+1,1) ~= '-' then do 'HUE_MASK' LoadImage Fix_Hue((i*42.667)+get_HueTol('L')) Fix_Hue((i*42.667)+get_HueTol('R')) MaskImage = Result 'MARK' AlphaImage 'SECONDARY' 'MARK' MaskImage 'PRIMARY' 'COMPOSITE' 0 0 'MAX' NewAlpha = Result 'CLOSE' AlphaImage 'CLOSE' MaskImage AlphaImage = NewAlpha end end 'CONVERT_TO_GREY' LoadImage GreyImage = Result 'MARK' AlphaImage 'ALPHA' 'MARK' LoadImage 'PRIMARY' 'MARK' GreyImage 'SECONDARY' 'COMPOSITE' 0 0 'ALPHA' OutputImage = Result 'CLOSE' GreyImage 'CLOSE' AlphaImage 'CLOSE' LoadImage if getclip('cfg_save_frmt')='' then setclip('cfg_save_frmt','ILBM CmpByteRun1') 'SAVE_DATA' OutputImage '"'dst_image'"' '"'getclip('cfg_save_frmt')'"' if (RC ~= 0) then do 'IE_TO_FRONT' 'REQUEST' '"Failed to save image:' d2c(10)||dst_image'"' '" OK "' return '<ERROR>' end 'CLOSE' OutputImage back = 'OK' return back /* Internal procedures ---------------------------------------------- */ Fix_Hue: parse arg Tol if Tol < 0 then Back = 255 + trunc(Tol) else if Tol > 255 then Back = trunc(Tol) - 255 else Back = trunc(Tol) return Back Get_HueTol: parse arg Type if Type = 'L' then do if WorkType = 0 then Back = LHueTol else do newi = i if newi=0 then newi = 6 if substr(Select,newi,1) ~= '-' then Back = -21 else Back = LHueTol end end else do if WorkType = 0 then Back = RHueTol else do newi = i+2 if newi=7 then newi = 1 if substr(Select,newi,1) ~= '-' then Back = 21 else Back = RHueTol end end return Back /*******************************************************************/ /* This is where control goes when an error code is returned by IE */ /* It puts up a message saying what happened and on which line */ /*******************************************************************/ error: if RC=5 then do IE_TO_FRONT LAST_ERROR 'REQUEST "'||RESULT||'"' end else do IE_TO_FRONT LAST_ERROR 'REQUEST "Error detected!!!'||D2C(10)||'Image Engineer error message is as follows'||D2C(10)||result||D2C(10)||'Script failed on line '||SIGL||'"' 'Doh!' end return '<ERROR>'